// CTask.h: interface for the CTask class.
//

#if !defined(AFX_SCHEDULEDTASK_H__A00D015F_9061_11D2_8D3B_FC17F33B2809__INCLUDED_)
#define AFX_SCHEDULEDTASK_H__A00D015F_9061_11D2_8D3B_FC17F33B2809__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afx.h>
#include <mstask.h>
#include <taskschd.h>

class CTask  
{
public:
	CTask();

    enum ETaskFrequency {
		freqUnset = 0,
		freqFirst = 0,
		freqOnce,
		freqDaily,
		freqWeekly,
		freqMonthly,
		freqAtLogon,
		freqLast = freqAtLogon
	};
	
	BOOL GetStartDateTime ( CTime& ) const;
	void SetStartDateTime ( const CTime& );
	void SetStartDateTime ( const SYSTEMTIME& );
	
	BOOL  GetEndDate ( CTime& ) const;
	void SetEndDate ( const CTime& );
	void SetEndDate ( const SYSTEMTIME& );
	
	ETaskFrequency GetFrequency() const;
	void SetFrequency ( ETaskFrequency );
	
	CString GetProgram() const;
	void SetProgram ( LPCTSTR szProgram );
	
	CString GetParameters() const;
	void SetParameters ( LPCTSTR szParams );
	
	CString GetStartingDir() const;
	void SetStartingDir ( LPCTSTR szDir );
	
	CString GetAccountName() const;
	void SetAccountName ( LPCTSTR szAccount );
	
	void SetPassword ( LPCTSTR szPassword );
	
	CString GetComment() const;
	void SetComment ( LPCTSTR szComment );

protected:
    SYSTEMTIME m_timeStart;
    SYSTEMTIME m_timeEnd;

    ETaskFrequency m_eFreq;

    CString    m_sProgramPath;
    CString    m_sParameters;
    CString    m_sStartingDir;
    CString    m_sAccount;
    CString    m_sPassword;
    CString    m_sComment;

public:
    void Reset();
	
	HRESULT SaveTask ( LPCTSTR szTaskName, BOOL bFailIfExists = FALSE ) const;
	static HRESULT DeleteTask ( LPCTSTR szTaskName );
	static HRESULT TaskExisted ( LPCTSTR szTaskName, BOOL& isFound );

public:
	virtual ~CTask();

protected:
	static BOOL GetVersionTS();
	HRESULT SaveTaskTS1 ( LPCTSTR szTaskName, BOOL bFailIfExists ) const;
	HRESULT SaveTaskTS2 ( LPCTSTR szTaskName, BOOL bFailIfExists ) const;
	static HRESULT DeleteTaskTS1 ( LPCTSTR szTaskName );
	static HRESULT DeleteTaskTS2 ( LPCTSTR szTaskName );
	static HRESULT TaskExistedTS1 ( LPCTSTR szTaskName, BOOL& isFound );
	static HRESULT TaskExistedTS2 ( LPCTSTR szTaskName, BOOL& isFound );
    WORD GetDayOfWeekFlag ( const SYSTEMTIME& ) const;
    BOOL m_bNT;
};

#endif // !defined(AFX_SCHEDULEDTASK_H__A00D015F_9061_11D2_8D3B_FC17F33B2809__INCLUDED_)